package com.itheima.servlet;

import com.itheima.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/loginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //获取参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        //通过对象设置数据
        User user=new User(username,password);
        //设置session数据
        request.getSession().setAttribute("u",user);
        //重定向到/hack.html页面
        response.sendRedirect("/hack.html");
    }
}